<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;

use App\Rpc\CalculatorServiceInterface;
use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\FooMiddleware;
use Hyperf\Utils\Context;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Contract\RequestInterface;
use App\Request\FooRequest;
use Hyperf\Di\Annotation\Inject;


/**
 * @AutoController()
 * @Middleware(FooMiddleware::class)
 * @property int $foo
 */
class IndexController extends AbstractController
{



    /**
     * @Inject()
     * @var FooRequest
     */
    private $fooRequest;

    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        return [
            'method' => $method,
            'message' => "Hello.woshihaoren",
        ];
    }


    public function get()
    {
        return $this->foo;
    }


    public function update(RequestInterface $request)
    {
        $foo = $request->input('foo');
        $this->foo = $foo;
        return $this->foo;


    }

    public function val()
    {

        $data = $this->fooRequest->validated();
        return $data;

    }



    public function __get($name)
    {
       return context::get(__CLASS__. ':' .$name);
    }

    public function __set($name, $value)
    {

        context::set(__CLASS__. ':' .$name,$value);

    }

    public function add(CalculatorServiceInterface $calculatorService)
    {
       return  $calculatorService->add(1,2);
    }



}
